<?php
/*
*All rights reserved: Json.
*Links:http://www.liyaoquan.cn.
*Links:http://imarkchina.cn.
*Links:http://www.imarkchina.cn.
*/

/**
 * 博客后台专题控制器，负责，业务流程判断
 * 后台所有操作都需要权限，必需继承 CommonAction 控制器
 */
Class GetpageAction extends CommonAction{

	/**
	 * 博客专题首页
	 * @return [type] [description]
	 */
	Public function index(){
		$M = M('Getpage')->index();
		$this->assign('plist', $M['plist']);
		$this->assign('page', $M['page']);
		$this->display();
	}

	/**
	 * 处理删除与排序
	 * @return [type] [description]
	 */
	Public function update(){
		if (ISPOST) {
			$postdel = trim(G('post.del'));
			if (!empty($postdel)) {
				$getpostid = G('post.id');
				if (empty($getpostid)) {
					$this->error('Shit，我有选择？');
				}
				if (M('Getpage')->UpdateAndDel(G('post.id'))) {
					$this->success('操作成功～！', U('index'));
				} else {
					$this->error('操作失败～！');
				}
				//删除操作
			} else {
				$checkpord = G('post.ord');
				if (empty($checkpord)) {
					$this->error('Shit，我有选择？');
				}
				if (M('Getpage')->UpdateAndDel(G('post.ord'), true)) {
					$this->success('操作成功～！', U('index'));
				} else {
					$this->error('操作失败～！');
				}
			}
		}
	}

	/**
	 * 添加专题页面
	 */
	Public function add(){
		M('Public')->putJsonFile();
		$check = false;
		$geteid = trim(G('get.eid'));
		if (!empty($geteid)) {
			$file = unfile(C('page.data').G('get.eid').'.Mark');
			$check = true;
			$this->assign('check', $check);
			$this->assign('file', $file);
		} else {
			$this->assign('check', $check);
			$this->assign('file', $file = array('ispl' => 1, 'index_show' => 1, 'ord' => 100));
		}
		$this->display();
	}

	/**
	 * 检查POST过来的数据，与分发给模型
	 * @return [type] [description]
	 */
	Public function checkdata(){
		if (ISPOST) {
			$posttitle = trim(G('post.title'));
			if (empty($posttitle)) {
				$this->error('Shit，标题居然没有填写～！');
			}
			$postcontent = trim(G('post.content'));
			if (empty($postcontent)) {
				$this->error('Oh,my Gog.内容不写就发布了～！');
			}
			if (M('Getpage')->CheckUPData(G('post.'))) {
				$config = M('Public')->blogConfig();
				if ($config['cacheing']) {
					$this->clearCache('page-'.G('post.id'));
				}
				$this->success('添加成功～！', U('index'));
			} else {
				$this->error('添加失败～！');
			}
		}
	}

	/**
	 * 删除操作
	 * @return [type] [description]
	 */
	Public function del(){
		if (M('Getpage')->delPage(G('get.id'))) {
			$this->success('操作成功～！', U('index'));
		} else {
			$this->error('操作失败～！');
		}
	}
}